<template>
	<view v-if="params.url">
		<web-view :webview-styles="webviewStyles" :src="`${params.url}`" @message="message"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {},
				webviewStyles: {
					progress: {
						color: "#FF3333"
					}
				}
			}
		},
		props: {
			src: {
				type: [String],
				default: null
			}
		},
		onLoad(event) {
			this.params = event
			if (event.title) {
				uni.setNavigationBarTitle({
					title: event.title
				})
			}
			if (this.params.progress == 'no') {
				this.webviewStyles = {}
			}
		},
		methods: {
			message(res) {
				if (res.type == 'message') {
					if (res.detail && res.detail.data && res.detail.data[0]) {

						if (res.detail.data[0]["action"] == "closeWebView") {
							uni.navigateBack({delta:1})
						}

					}
				}
			}
		}
	}
</script>